package cn.dg.manager.goods.goodsIntroduction.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.dg.manager.common.dao.impl.BaseDaoImpl;
import cn.dg.manager.common.entity.PageEntity;
import cn.dg.manager.goods.goodsClassify.dao.GoodsTypeDao;
import cn.dg.manager.goods.goodsClassify.entity.GoodsType;
import cn.dg.manager.goods.goodsIntroduction.dao.GoodsInfoDao;
import cn.dg.manager.goods.goodsIntroduction.entity.GoodsInfoVO;

@Repository("GoodsInfoDao")
public class GoodsInfoDaoImpl extends BaseDaoImpl implements GoodsInfoDao {

	// SQL 路径
	public static final String GOODS_INFO_SQL_PACKAGE = GoodsInfoDao.class.getName().concat(".");
	
	/**
	 * 检索商品基本信息
	 */
	public PageEntity<GoodsInfoVO> findGoodsInfoListPage(Map<String, Object> params) {
		PageEntity<GoodsInfoVO> page = new PageEntity<GoodsInfoVO>();
		int pg = params.get("page") != null ? Integer.parseInt(String.valueOf(params.get("page"))) : START_PAGE_INDEX;
		page.setPageNo(pg);
		page.setParams(params);
		int i = params.get("rows") != null ? Integer.parseInt(String.valueOf(params.get("rows"))) : END_PAGE_INDEX;
		page.setPageSize(i);
		page.setParams(params);
		List<GoodsInfoVO> goodsInfoList = this.sqlSessionTemplate.selectList(GOODS_INFO_SQL_PACKAGE.concat("findGoodsInfoListPage"), page);
		page.setResults(goodsInfoList);
		return page;
	}

	/**
	 * 增加商品基本信息
	 */
	public long insertGoodsInfo(GoodsInfoVO bean) {
		return (long) this.sqlSessionTemplate.insert(GOODS_INFO_SQL_PACKAGE.concat("insertGoodsInfo"), bean);
	}

	/**
	 * 更新商品基本信息
	 */
	public long updateGoodsInfo(GoodsInfoVO bean) {
		return (long) this.sqlSessionTemplate.insert(GOODS_INFO_SQL_PACKAGE.concat("updateGoodsInfo"), bean);
	}
	/**
	 * 删除商品基本信息
	 */
	public long deleteGoodsInfo(List<String> goodsIdList) {
		return (long) this.sqlSessionTemplate.insert(GOODS_INFO_SQL_PACKAGE.concat("deleteGoodsInfoByIdList"), goodsIdList);
	}

	/**
	 * 根据主键查询数据
	 */
	public GoodsInfoVO findGoodsInfoById(Map<String, Object> condMap) {
		GoodsInfoVO vo = this.sqlSessionTemplate.selectOne(GOODS_INFO_SQL_PACKAGE.concat("findGoodsInfoById"), condMap);
		return vo;
	}

	/**
	 * 更新商品图片信息
	 */
	public long updateGoodsImageInfo(Map<String, Object> condMap) {
		return (long) this.sqlSessionTemplate.insert(GOODS_INFO_SQL_PACKAGE.concat("updateGoodsImageInfo"), condMap);
	}
}
